part of '../repository.dart';

const _kPurchasedSubscriptionInfoAbsentPriceChangeStatusValue = 'absent';
const _kPurchasedSubscriptionInfoAcceptedPriceChangeStatusValue = 'accepted';
const _kPurchasedSubscriptionInfoPendingPriceChangeStatusValue = 'pending';

class _PurchasedSubscriptionInfoPriceChangeStatusDto extends Equatable {
  const _PurchasedSubscriptionInfoPriceChangeStatusDto._internal({
    required this.priceChangeStatusString,
  });

  final String priceChangeStatusString;

  @override
  List<Object?> get props {
    return [
      priceChangeStatusString,
    ];
  }

  factory _PurchasedSubscriptionInfoPriceChangeStatusDto.fromString(
      String priceChangeStatusString) {
    return _PurchasedSubscriptionInfoPriceChangeStatusDto._internal(
      priceChangeStatusString: priceChangeStatusString,
    );
  }

  factory _PurchasedSubscriptionInfoPriceChangeStatusDto.fromEntity(
      GooglePlayPurchasedSubscriptionInfoPriceChangeStatus priceChangeStatus) {
    late final String priceChangeStatusString;

    if (priceChangeStatus == GooglePlayPurchasedSubscriptionInfoPriceChangeStatus.absent) {
      priceChangeStatusString = _kPurchasedSubscriptionInfoAbsentPriceChangeStatusValue;
    } else if (priceChangeStatus == GooglePlayPurchasedSubscriptionInfoPriceChangeStatus.accepted) {
      priceChangeStatusString = _kPurchasedSubscriptionInfoAcceptedPriceChangeStatusValue;
    } else if (priceChangeStatus == GooglePlayPurchasedSubscriptionInfoPriceChangeStatus.pending) {
      priceChangeStatusString = _kPurchasedSubscriptionInfoPendingPriceChangeStatusValue;
    }

    return _PurchasedSubscriptionInfoPriceChangeStatusDto._internal(
      priceChangeStatusString: priceChangeStatusString,
    );
  }

  @override
  String toString() {
    return priceChangeStatusString;
  }

  GooglePlayPurchasedSubscriptionInfoPriceChangeStatus toEntity() {
    if (priceChangeStatusString == _kPurchasedSubscriptionInfoAbsentPriceChangeStatusValue) {
      return GooglePlayPurchasedSubscriptionInfoPriceChangeStatus.absent;
    } else if (priceChangeStatusString ==
        _kPurchasedSubscriptionInfoAcceptedPriceChangeStatusValue) {
      return GooglePlayPurchasedSubscriptionInfoPriceChangeStatus.accepted;
    } else if (priceChangeStatusString ==
        _kPurchasedSubscriptionInfoPendingPriceChangeStatusValue) {
      return GooglePlayPurchasedSubscriptionInfoPriceChangeStatus.pending;
    }

    throw UnimplementedError();
  }
}
